from database.db_reader import GetTagMsg
import pandas as pd

# 查询信息
def get_tag_msg_by_reader(reader_no, start_time, end_time):
    tag_msg_list = []
    for number in GetTagMsg(reader_no).get_tag_battery_voltage():
        info = {}
        info['reader_id'] = number[2]
        info['绑定状态'] = GetTagMsg(number[2]).get_reader_binding_start()
        info['tag_id'] = number[3]
        info['电量'] = number[5]
        info['电量状态'] = number[6]
        info['信号质量'] = GetTagMsg(number[2]).rssi(number[3])
        info['串口丢包率'] = GetTagMsg(number[2]).get_tag_loss_rate(number[3], start_time, end_time)
        tag_msg_list.append(info)
    tag_msg_pd = pd.DataFrame(tag_msg_list)
    order = ['reader_id', 'tag_id', '电量', '电量状态', '信号质量', '串口丢包率', '绑定状态']
    tag_msg_pd = tag_msg_pd[order]
    return tag_msg_pd

    # return tag_msg_list


if __name__ == '__main__':
    start_time = "2019-04-17 00:00:00"
    end_time = "2019-04-17 23:59:59"
    reader_no = '200004'
    tag_msg_list = get_tag_msg_by_reader(reader_no, start_time, end_time)
    print(tag_msg_list)
    pass
